Skip to content

PYTHON-5856 Move cursor execution logic into cursor class#2894

Open
aclark4life wants to merge 7 commits into
mongodb:masterfrom
aclark4life:PYTHON-5856
Open

PYTHON-5856 Move cursor execution logic into cursor class#2894
aclark4life wants to merge 7 commits into
mongodb:masterfrom
aclark4life:PYTHON-5856

Conversation

@aclark4life

@aclark4life aclark4life commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

PYTHON-5856

Changes in this PR

Moves the command preparation and response construction that lived in Server.run_operation into _AsyncCursorBase._run_with_conn, completing the consolidation started in PYTHON-5676. Cursors now call run_cursor_command directly without routing through Server.

  • Extract _CURSOR_DOC_FIELDS and _split_message (in cursor_shared.py) and _operation_to_command (in cursor_base.py) as module-level helpers
  • Add abstract _unpack_response to _AsyncCursorBase to make the interface explicit
  • Add _run_with_conn (carrying the @_handle_reauth decorator) to _AsyncCursorBase — new home for all of Server.run_operation's logic
  • client._run_operation's second parameter, previously unpack_res (only decoded the wire response), is replaced by run_with_conn(conn, operation, read_preference) -> Response, which executes the whole operation instead of routing through server.run_operation; callers (cursor.py, command_cursor.py) pass self._run_with_conn
  • Remove Server.run_operation, Server.operation_to_command, and Server._split_message entirely
  • The returned Response/PinnedResponse now takes its address from conn.address instead of Server._description.address. These are equivalent (the connection belongs to the selected server's pool), and conn.address is the more direct source now that the logic lives on the cursor rather than the Server.

PYTHON-5745 (#2891) merged into master and was picked up here via a merge from master. That merge left Server.run_operation/operation_to_command (and their now-orphaned imports) unreconciled since master no longer had the caller this branch had moved to cursor_base.py; this PR removes that leftover code and drops the address/start args from _run_with_conn's call to run_cursor_command, matching the new _CommandTelemetry-based signature.

Test Plan

No new tests — this is a behavior-preserving refactor. The existing spec suites (APM/command-monitoring, auth, cursor) assert the exact behavior that any regression would change. Updated test_stale_getmore to use the run_with_conn parameter name.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)? — Not necessary; internal refactor with no user-facing behavior change.
  • Is there test coverage? — Covered by existing spec suites.
  • Is any followup work tracked in a JIRA ticket? If so, add link(s). — N/A

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

This comment was marked as outdated.

@codecov-commenter

This comment was marked as off-topic.

This comment was marked as resolved.

This comment was marked as outdated.

Move the command preparation and response construction that lived in
Server.run_operation into _AsyncCursorBase._run_with_conn, so cursors
call run_cursor_command directly without routing through Server.

- Extract _CURSOR_DOC_FIELDS, _split_message, and _operation_to_command
  as module-level helpers in cursor_base.py
- Add abstract _unpack_response to _AsyncCursorBase to make the
  interface explicit
- Add _run_with_conn (carrying the @_handle_reauth decorator) to
  _AsyncCursorBase; this is the new home for all of run_operation's logic
- client._run_operation now accepts execute_fn(conn, op, rp) -> Response
  instead of routing through server.run_operation
- Remove Server.run_operation, Server.operation_to_command, and
  Server._split_message entirely

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

The execute_fn -> run_with_conn rename missed this call site.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.

@aclark4life aclark4life marked this pull request as ready for review July 1, 2026 19:42
@aclark4life aclark4life requested a review from a team as a code owner July 1, 2026 19:42
@aclark4life aclark4life requested a review from sleepyStick July 1, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants